class RpcData {

    constructor(path, version, status, extDataMap, data) {
        this.path = path;
        this.extDataMap = extDataMap;
        this.version = version;
        this.status = status;
        this.data = data;
    }

    static build(path, data, seq) {
        let extDataMap = new Map();
        extDataMap.set("localSeq", seq);

        return new RpcData(path, 1, 0, extDataMap, data);
    }
}

class Dto {

    // 标识符
    getLocalSeq() {
        return '';
    }
}

class Req extends Dto {

    constructor(localSeq) {
        super();
        this.localSeq = localSeq;
        this.createDateTime = new Date();
    }

    getLocalSeq() {
        return this.localSeq;
    }
}

class TenantReq extends Req {

    constructor(tenantCode, terminalType, localSeq) {
        super(localSeq);
        this.tenantCode = tenantCode;
        this.terminalType = terminalType;
    }
}

class WebRtcLoginReq extends TenantReq {

    constructor(userId, authToken, tenantCode, terminalType) {
        super(tenantCode, terminalType, "0");
        this.authToken = authToken;
        this.userId = userId;
    }
}

class WebRtcRoomReq extends Req {
    constructor(props) {
        super(props);
        this.roomName = null;
        this.userId = null;
    }

}
class WebRtcCreateRoomReq extends WebRtcRoomReq {
    constructor(props) {
        super(props);
        this.chatType = ChatType.audio;
        this.terminalType = null;
        this.machineInfo = null;
        this.width = null;
        this.height = null;
    }
}

class WebRtcJoinRoomReq extends WebRtcRoomReq {
    constructor(props) {
        super(props);
        this.terminalType = null;
        this.machineInfo = null;
        this.width = null;
        this.height = null;
    }
}

class WebRtcExitRoomReq extends WebRtcRoomReq {
    constructor(props) {
        super(props);
    }
}

class WebRtcP2pCandidateReq extends WebRtcRoomReq {
    constructor(props) {
        super(props);
        this.toUserId = null
        this.iceCandidate = null;
    }
}

class WebRtcP2pSdpReq extends WebRtcRoomReq {
    constructor(props) {
        super(props);
        this.toUserId = null
        this.sdp = null;
        this.sdpType = null;
    }
}

class WebRtcCancelReq extends Req {
    constructor(props) {
        super(props);
        this.userIds = null
    }
}

class WebRtcRoomInfo {
    constructor(props) {
        this.name = null;
        this.ownerUserId = null;
        this.userInfoList = [];
    }
}

class WebRtcUserInfo {
    constructor(props) {
        this.terminalType = null;
        this.machineInfo = null;
        this.width = null;
        this.height = null;
    }
}

class IceCandidate {
    constructor(props) {
        this.sdpMid = null;
        this.sdpMLineIndex = -1;
        this.candidate = null;
        this.serverUrl = null;
    }
}

class PongResp {

}

class Resp extends Dto {

    constructor(props) {
        super();
        this.localSeq = '';
        this.successDataTime = new Date();
    }
}

class OkResp extends Resp {

    constructor(props) {
        super();
        this.short = 0;
        this.otherInfo = null;
    }
}

const TerminalType = {
    pc: 'pc',
    android : 'android',
    ios : 'ios',
    pad : 'pad',
    ipad : 'ipad',
    web : 'web',
    hm : 'hm',
}

const ChatType = {
    audio: 1,        // 语言聊天
    video: 2,        // 视频聊天
    sharing: 3,      // 共享资料
}

const SdpType = {
    offer: 'offer',        // 语言聊天
    answer: 'answer',           // 视频聊天
}

class ExceptionResp{

    constructor(errorStatus) {
        this.errorStatus = errorStatus;
    }
}

class RpcException extends Error {

    constructor(exceptionResp) {
        super();
        this.exceptionResp = exceptionResp;
    }
}

class TimeoutException extends Error {

    constructor(rpcData, message) {
        super();
        super.message = message;
        this.rpcData = rpcData;
    }
}

class ConnectionException extends Error {

    constructor(message) {
        super();
        super.message = message;
    }
}


